package com.example.administrator.gifdemo;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.annotation.RequiresApi;
import android.util.Log;

/**
 * 创建者     ZCL
 * 创建时间   2018/10/8 17:31
 * 描述	      ${TODO}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@SuppressLint("OverrideAbstract")
public class MyNotifiService extends NotificationListenerService {

    private String           nMessage;
    private String           data;

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("KEVIN", "Service is started" + "-----");
        data = intent.getStringExtra("data");

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        //        super.onNotificationPosted(sbn);
        try {
            //有些通知不能解析出TEXT内容，这里做个信息能判断
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                if (sbn.getNotification().tickerText != null) {
                    nMessage = sbn.getNotification().tickerText.toString();
                    Log.i("swl", "Get Message" + "-----" + nMessage);
                }
            }
        } catch (Exception e) {
            // Toast.makeText(MyNotifiService.this,"不可解析的通知",Toast.LENGTH_SHORT).show();
            Log.e("swl", "不可解析的通知");

        }

    }
}
